//
//  ColumnListTableViewCell.m
//  PlayerFix
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "ColumnListTableViewCell.h"
#import "ColumnListModel.h"
@implementation ColumnListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    self.posterImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 60, 80)];
    [self.contentView addSubview:self.posterImageView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 10, 270, 20)];
    [self.contentView addSubview:self.titleLabel];
    
    
    UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 30, 270, 20)];
    [self.contentView addSubview:aLabel];
    aLabel.text = @"评分";
    aLabel.textColor = [UIColor darkGrayColor];
    aLabel.font = [UIFont systemFontOfSize:13];
    self.ratingLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 30, 270, 20)];
    [self.contentView addSubview:self.ratingLabel];
    
    self.tagsLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 50, 270, 40)];
    [self.contentView addSubview:self.tagsLabel];
    
}

- (void)setColumnListModel:(ColumnListModel *)columnListModel{
    
    if (_columnListModel != columnListModel) {
        [_posterImageView sd_setImageWithURL:[NSURL URLWithString:columnListModel.poster] placeholderImage:[UIImage imageNamed:@"holderPic_recommend.png"]];
        
        NSString *title = [NSString stringWithFormat:@"%@ (%@)",columnListModel.title,columnListModel.year];
        self.titleLabel.text = title;
        self.titleLabel.font = [UIFont systemFontOfSize:13];
        
        /**********评分星星***********/
        UIImageView *imageView1 = [[UIImageView alloc]init];
        imageView1.frame = CGRectMake(110, 32, 75, 15);
        imageView1.image = [UIImage imageNamed:@"rating_gray"];
        [self.contentView addSubview:imageView1];
        NSNumber *number = [columnListModel valueForKey:@"rating"];
        float bi = number.floatValue / 10.0;
        
        UIImageView *imageTemp2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rating"]];
        UIImage  *image1  = [UIImage imageNamed:@"rating"];
        
        CGImageRef imageRef  = image1.CGImage;
        
        CGImageRef image2 = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, imageTemp2.frame.size.width*bi*2, imageTemp2.frame.size.height*2));
        
        UIImageView *imageView2 = [[UIImageView alloc]init];
        imageView2.frame = CGRectMake(0, 0, imageView1.frame.size.width * bi, imageView1.frame.size.height);
        imageView2.image = [UIImage imageWithCGImage:image2];
        
        [imageView1 addSubview:imageView2];
        /**********评分星星***********/
        
        NSString *rating = [NSString stringWithFormat:@"%@ (%@人评)",columnListModel.rating,columnListModel.rating_count];
        _ratingLabel.text = rating;
        _ratingLabel.font = [UIFont systemFontOfSize:13];
        _ratingLabel.textColor = [UIColor darkGrayColor];
        
        _tagsLabel.text = columnListModel.tags;
        _tagsLabel.numberOfLines = 2;
        _tagsLabel.font = [UIFont systemFontOfSize:13];
        _tagsLabel.textColor = [UIColor darkGrayColor];
    }
    
}



@end
